﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Model.Admin.Order;

namespace OnlineFloralShop.Admin.Order
{
    public partial class OrderDetails : System.Web.UI.Page
    {
     
        public string str;
        public string sql = "";
        Model.Admin.Order.Order order = new Model.Admin.Order.Order();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                if (Request.QueryString["Id"] != null)
                {
                    str = Request.QueryString["Id"].ToString();
                    order.FillListView(listorder, order.getOrderOfCus(str));
                }


                else
                {
                    order.FillListView(listorder, order.lisorder());
                }
                
            }
            DataTable table = Model.Common.DataAccess.GetData(null, null, "getAllLocation");
            orderLocation.DataSource = table;
            orderLocation.DataValueField = "LocationName";
            orderLocation.DataBind();

        }
        protected string getsql() 
        {
            sql = "SELECT Orders.OrderId ,aspnet_Users.UserName,Orders.[Time],Orders.Status,Orders.[Name],Orders.Address,Orders.Phone,Orders.Email ";
            string from = " FROM Orders, aspnet_Users ";
            string where = " WHERE Orders.UserId=aspnet_Users.UserId";
            if (searchorderId.Text != "")
            {
                where += " and Orders.OrderId like '" + searchorderId.Text + "'";
            }
            if (searchorderUser.Text != "")
            {
                where += " and aspnet_Users.UserName like '" + searchorderUser.Text + "'";
            }
            if (orderstartdate.Text != "")
            {
                where += " and Orders.StartDate = '" + orderstartdate.Text + "'";
            }
            if (orderenddate.Text != "")
            {
                where += " and Orders.EndDate = '" + orderenddate.Text + "'";
            }
            if (ordertime.Text != "")
            {
                where += " and Orders.[Time] = '" + ordertime.Text + "'";
            }
            if (orderaddress.Text != "")
            {
                where += " and Orders.Address like '" + orderaddress.Text + "'";
            }
            if (orderLocation.SelectedValue != "")
            {
                from += ",Locations";
                where += " and Orders.LocationId= Locations.LocationId and Locations.LocationName = '" + orderLocation.SelectedValue + "'";
            }
            return sql + from + where;
        }
        protected void SearchOrderByCusname(object sender, EventArgs e)
        {
            order.FillListView(listorder, order.searchOrderByCusName(this.txtordersearch.Text.Trim()));
        }
        protected void orderSearch_click(object sender, EventArgs e)
        {
            
            order.FillListView(listorder, order.SearhOrderByfilter(getsql()));

        }
    }
}
